package com.hoopchina.ui.search;

import java.util.LinkedList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

/**
 * SearchRecordListAdapter
 * 用于加载搜索历史页面的 列表
 * 
 * @author Guo Baiyu
 */
public class SearchRecordListAdapter extends BaseAdapter {
//    private LinkedList<TextListItem> mList = null;
    private List<SearchRecord> mDataList ;
    private Context mContext ;
    /**
     * 
     * @param context
     */
    public SearchRecordListAdapter( Context context ) {
        super();
//        mList = new LinkedList<TextListItem>();
        mDataList  = new  LinkedList<SearchRecord>();
        mContext = context;
    }

    /**
	 * 
	 */
    @Override
    public int getCount() {
        return mDataList.size();
    }

    /**
	 * 
	 */
    @Override
    public Object getItem( int position ) {
        return mDataList.get( position );
    }

    /**
	 * 
	 */
    @Override
    public long getItemId( int position ) {
        return position;
    }

    /**
	 * 
	 */
    @Override
    public View getView( int position, View convertView, ViewGroup parent ) {
    	SearchRecordListTextItem itemView = null;
    	if (convertView == null) {
    		itemView = new SearchRecordListTextItem(mContext);
    	}
    	else {
    		itemView = (SearchRecordListTextItem)convertView;
    	}

    	itemView.setItemText( mDataList.get( position ).getSearchRecordText() );
    	itemView.setDeletButotnTag( mDataList.get( position ).getSearchRecordText() );
    	itemView.setOnSearchHistoryDeleteItemButtonClickListener( new SearchHistoryDeleteItemButtonClickListener( (SearchView)mContext ) );
        return itemView;
    }

    /**
     * 
     * @param itemView
     */
    public void addItem( SearchRecord itemView ) {
    	mDataList.add( itemView );

        this.notifyDataSetChanged();
    }
    /**
     * 
     * @param itemView
     */
    public void addAllItem( List<SearchRecord> dataList) {
    	mDataList.addAll( dataList );
        this.notifyDataSetChanged();
    }

//    /**
//     * 
//     * @param itemView
//     */
//    public void deleteItem( TextListItem itemView ) {
//        mList.remove( itemView.getId() );
//        this.notifyDataSetChanged();
//    }
}
